<template>
  <router-view></router-view>
</template>

<script>
import { sendPong, sendWSPush} from "@/assets/ws/ws";
import ezws from "@/assets/ws/ezws";
export default {
  name: "ez-layout-root",
  created() {
    ezws.init()
    //websocket注册用户
    let msg = ezws.createMessage()
    msg.business = ezws.businessType.reg
    msg.content = this.$ezstore.auth.getToken()
    sendWSPush(msg)
    window.addEventListener('onmessageWS', this.getSocketData)

    if (this.$route.path === "/") {
      this.$router.push(
          this.$ezstore.auth.getIsLogin() ?
              "/index" : "/login"
      )
    }
  },
  destroyed() {
    window.removeEventListener('onmessageWS', this.getSocketData)
  },
  methods:{
    getSocketData(v) {
      //心跳回应
      if (v.detail.data === "ping"){
        sendPong()
      }
    },
  }
}
</script>

<style scoped>

</style>